package me.util;

import java.util.ArrayList;
import java.util.Random;

public class CodeUtil {
    public static String getCode() {
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char) ('a' + i));
        }
        for (int i = 0; i < 26; i++) {
            list.add((char) ('A' + i));
        }
        String result = "";
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            int index = r.nextInt(list.size());
            result += list.get(index);
        }
        int number = r.nextInt(10);
        result += number;
        char[] chars = result.toCharArray();
        int randomIndex = r.nextInt(chars.length);

        char temp = chars[4];
        chars[4] = chars[randomIndex];
        chars[randomIndex] = temp;
        return new String(chars);
    }
}
